#include "ui_flexeffect.h"
#include "ui_manager.h"

#include "audio/audio.h"

#include "util/timer.h"		    // Needs to come in early
#include "util/mmgr.h"		    // Needs to come in early
#include "util/common_macros.h"		// macros
#include "util/log.h"		    // logging

#include "script/scripthelper.h"
#include "script/write_lua.h"

#ifdef _ENABLE_LUABIND
#include <luabind/luabind.hpp>
#endif // _ENABLE_LUABIND

using namespace ui;
using namespace script;



//UIFlexEffect: Constructor and destructor
//======================================================================================================================
UIFlexEffect::UIFlexEffect(UIWidget* pParent,const std::string& Name):
	UIWidget(pParent, Name)
{
	m_pTickFunc = NULL;
	m_pRenderFunc = NULL;
	m_Type = WT_FLEXEFFECT;

}//UIFlexEffect::UIFlexEffect(UIWidget* pParent,const std::string& Name = "")



UIFlexEffect::~UIFlexEffect()
{

	//params uninit

}//UIFlexEffect::~UIFlexEffect()



//UIFlexEffect: Common routines
//======================================================================================================================

bool UIFlexEffect::Create(const std::string& Name, const math::Vec2& Pos, const math::Vec2& Size)
{

	UIWidget::Create(Name, Pos, Size);
	// create progress stuff

	return true;


}//bool UIFlexEffect::Create(const std::string& Name, const math::Vec2& Pos, const math::Vec2& Size)


bool UIFlexEffect::Load(LuaPlus::LuaObject& _LObj)
{

	UIWidget::Load(_LObj);	// get all the common stuff loaded
	
	//polyline-specific stuff


	////line width
	//m_LineWidth = ScriptHelper::GetTableVec2(_LObj, "LineWidth", math::Vec2(1.0f/800.0f, 1.0f/600.0f));

	////line points
	//LuaObject PointsTable = ScriptHelper::GetObj(_LObj, "Points");

	//if (PointsTable.IsTable() == true)
	//{
	//	int i;
	//	int PointsCount = PointsTable.GetCount();

	//	if (PointsCount > 1)
	//	{

	//		for (i = 0; i < PointsCount; i++)
	//			m_LinePoints.push_back(ScriptHelper::GetVec2(PointsTable[i+1], math::Vec2(0.0f,0.0f)));
	//	}
	//}
	//
	////line segment sprite settings
	////image
	//std::string SegmentImage = ScriptHelper::GetTableString(_LObj, "SegmentImage");

	//if (SegmentImage != "")
	//	m_SpriteSegment.SetImage(SegmentImage);

	////color
	//m_SegmentColor = ScriptHelper::GetTableVec4(_LObj, "SegmentColor", math::Vec4(1.0f,1.0f,1.0f,1.0f));

	////additive
	//m_SpriteSegment.SetAdditive(ScriptHelper::GetTableBool(_LObj, "SegmentAdditive", false)); 	

	////UVs
	//m_SpriteSegment.SetUV();

	return true;
}





//UIFlexEffect: Update and Render
//======================================================================================================================


bool UIFlexEffect::Tick(float dt)
{
	UIWidget::Tick(dt);	// tick children, etc

	if (m_pTickFunc != NULL)
		return m_pTickFunc(dt);

	return true;
}




bool UIFlexEffect::Render(bool Force)
{

	UIWidget::Render(Force); //rendering common stuff

	if (!Force)
	{
		// look for things that could disqualify this one from being rendered
		if (!m_IsVisible)
			return false;	// disable entire widget
		if (m_pManager->GetDragTarget() == this)
			return false;	// will get rendered on top anyways
	}

	if (m_pRenderFunc != NULL)
		return m_pRenderFunc(Force);

	return true;
}

void UIFlexEffect::Register(LuaPlus::LuaState* _pScript)
{

#ifdef _ENABLE_LUABIND
   
#endif // _ENABLE_LUABIND    

}//void UIFlexEffect::Register(LuaPlus::LuaState* _pScript)
